Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "H+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "S+": this.getMilliseconds()
    };

    //test()方法用于检测一个字符串是否匹配某个模式.
    //因为date.getFullYear()出来的结果是number类型的,所以为了让结果变成字符串型，下面有两种方法：
    if (/(y+)/.test(fmt)) {
        //第一种：利用字符串连接符“+”给date.getFullYear()+""，加一个空字符串便可以将number类型转换成字符串。
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            //第二种：使用String()类型进行强制数据类型转换String(date.getFullYear())，这种更容易理解。
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(String(o[k]).length)));
        }
    }
    return fmt;
};

var nowPage = 1;

function doHasData(data) {
    var mybody = $("#spotlist");
    // mybody.empty();
    dbs = data.resmsg
    for (var item in dbs) {
        console.log(dbs[item].header);
        // var li = document.createElement("li");
        // li.className = "list-group-item";
        var obj = ' \
        <li class="list-group-item list-group-item-action d-flex flex-row justify-content-between p-3 my-2" data-bs-toggle="tooltip" title="'+ dbs[item].info + '"> \
        <div class="d-flex flex-row"> \
            <div class="d-flex flex-column justify-content-start align-items-center"> \
                <i class="fa fa-cloud-download p-5 border border-1 border-primary rounded-2" \
                    style="font-size:80px;color:rgb(102, 102, 102);"></i> \
                <span class="m-2">'+ dbs[item].filename + '</span> \
            </div> \
            <div class="d-flex flex-column align-content-center p-3"> \
                <h1>'+ dbs[item].name + '</h1> \
                <h5>分组标签:'+ dbs[item].sorth + '</h5> \
                <h5>上传人员:'+ dbs[item].answer + '</h5> \
                <h5>上传时间:'+ dbs[item].creattime + '</h5> \
            </div> \
        </div> \
        <div class="d-flex flex-column justify-content-center"> \
            <a class="btn btn-secondary" href="'+ dbs[item].header + '" target="_blank"> \
                <i class="fa fa-download fa-lg"></i> Download</a> \
        </div> \
        </li> '
        mybody.append(obj);
    }
}


function doSearch(key) {
    $.ajax({
        url: "/file/upload/",
        type: "GET",
        data: {
            "search": key,
            "page": nowPage
        },
        success(result, status, xhr) {
            // console.log(status);
            if (status == "success") {
                $("#spotlist").empty();
                doHasData(result);
            }
        },
        error(xhr, status, error) {
            // console.log(status);
            nowPage = 1
        }
    });
}


$(document).ready(function () {
    // 初始化容器高度
    var windowHeight = $(window).height();
    // console.log(windowHeight);
    // $("#spotlist").height(100);
    // 初始化控件
    //var date = new Date().Format("yyyy-MM-dd");
    $("#myDate").val("2000-01-01");

    $("#myDate").on("change", function () {
        var that = $(this).val();
        doSearch(that);
    });

    $("#doSearch").on("click", function () {
        var that = $("#mySearch").val();
        if (!that) { return }
        doSearch(that);
    });


});